package io.light.frame.samples.generator;

import com.alibaba.druid.pool.DruidDataSource;
import io.light.frame.dal.mybatis.generator.autoconfigure.annotation.EnableMybatisGen;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * Samples generator starter
 *
 * @author Ivan
 * @version 1.0.0
 * @date 2021-06-13 13:16
 */
@EnableMybatisGen
@EnableConfigurationProperties(DataSourceProperties.class)
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class SamplesGenStarter {

    public static void main(String[] args) {
        SpringApplication.run(SamplesGenStarter.class, args);
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    public DruidDataSource dataSource(DataSourceProperties properties) {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(properties.getUrl());
        dataSource.setUsername(properties.getUsername());
        dataSource.setPassword(properties.getPassword());
        dataSource.setValidationQuery("select 1");
        return dataSource;
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    public DruidDataSource dataSource_0(DataSourceProperties properties) {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(properties.getUrl());
        dataSource.setUsername(properties.getUsername());
        dataSource.setPassword(properties.getPassword());
        dataSource.setValidationQuery("select 1");
        return dataSource;
    }

    @Bean(initMethod = "init", destroyMethod = "close")
    public DruidDataSource dataSource_1(DataSourceProperties properties) {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(properties.getUrl());
        dataSource.setUsername(properties.getUsername());
        dataSource.setPassword(properties.getPassword());
        dataSource.setValidationQuery("select 1");
        return dataSource;
    }
}
